﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Dashboard
{
    /// <summary>
    /// Interaction logic for TaskView.xaml
    /// </summary>
    public partial class TaskView : UserControl
    {

        private static TaskView instance;

        public static TaskView GetTaskView()
        {
            if(instance == null)
            {
                instance = new TaskView();
            }
            return instance;
        }

        private TaskView()
        {
            InitializeComponent();
        }

        private void ListView_Initialized(object sender, EventArgs e)
        {
            
            //
            for (int i = 0; i < TaskManage.GetTaskNum(); i++)
            {
                TaskListView.Items.Add(i.ToString() + ".   " + TaskManage.GetTaskFromIndex(i).name);
            }
  
        }


        private void TaskListView_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {

            //
            int index = TaskListView.SelectedIndex;
            int work_offset = -1;
            if(index>0)
            {
                // web browser
                TaskhtmlBrowser.Navigate(TaskManage.GetTaskFromIndex(index + work_offset).htmlFilePath);

                TaskManage.GetTaskFromIndex(index + work_offset).Refresh();
                //basic information
                TaskBasicTextBox.Clear();
                TaskBasicTextBox.AppendText("TaskName: " + TaskManage.GetTaskFromIndex(index + work_offset).name + Environment.NewLine);
                TaskBasicTextBox.AppendText("LastTime: " + TaskManage.GetTaskFromIndex(index + work_offset).LastTime.ToString() + Environment.NewLine);
                TaskBasicTextBox.AppendText("NextTime: The task should be done by " + TaskManage.GetTaskFromIndex(index + work_offset).GetNextTime().ToString() + Environment.NewLine);
                if (TaskManage.GetTaskFromIndex(index + work_offset).GetDelayTime() == 0)
                {
                    TaskBasicTextBox.AppendText("DelayTo: The task hasn't been delayed");
                }
                else 
                {
                    TaskBasicTextBox.AppendText("DelayTo: The task has been delayed to " + TaskManage.GetTaskFromIndex(index + work_offset).GetDelyTo().ToString());
                }
                
            }

        }

        private void TaskBasicTextBox_Initialized(object sender, EventArgs e)
        {
            TaskBasicTextBox.IsReadOnly = true;
        }


    }

}
